#include"stdio.h"#include"stdlib.h"#include"string.h"int main(){int i = 0;int j = 0;int a[10][10] = { 0 };for (i = 0; i <= 9; i++){for (j = 0; j <= 9; j++){if (j == 0){a[i][0] = 1;}if (i == j){a[i][j] = 1;}}}for (i = 2; i <= 9; i++){for (j = 1; j <= i - 1; j++)//去掉每行的首尾两个元素{a[i][j] = a[i - 1][j - 1] + a[i - 1][j];}}for (i = 0; i <= 9; i++){for (j = 1; j <= 9 - i; j++)printf(" ");for (j = 0; j <= i; j++)printf("%5d", a[i][j]);printf("\n");}system("pause");return 0;}
c语言中关于杨辉三角问题
最新推荐文章于 2022-09-09 12:04:32 发布